package TetrisFlash 
{
	import starling.events.EnterFrameEvent;
	import starling.events.Event;
	import TetrisFlash.GameLoadData.SoundManager;
	
	import TetrisFlash.Screen.Welcome;
	/**
	 * ...
	 * @author DANTRUONG
	 */
	public class TetrisGame extends Game 
	{
		
		public function TetrisGame() 
		{
			super();
			this.addEventListener(Event.ADDED_TO_STAGE, onInit);
		}
		
		private function onInit(event:Event):void 
		{
			this.removeEventListener(Event.ADDED_TO_STAGE, onInit);
			
			//TODO: Init data, sounds and something...
			soundManager = SoundManager.getInstance();
			//Create start Screen
			setScreen(Welcome);
			
			this.stage.addEventListener(Event.ENTER_FRAME, onGameLoop);
		}
		
		private function onGameLoop(event:EnterFrameEvent):void 
		{
			updateGame(event.passedTime);
			drawGame();
		}
		
		override protected function updateGame (deltaTime: Number):void {
			super.updateGame(deltaTime);
			curScreen.updateScreen(deltaTime);
		}
		
		override protected function drawGame ():void {
			curScreen.drawScreen();
		}
		
		override protected function releaseGame ():void {
			curScreen.destroyScreen();
		}
		
	}

}